""""""""""""""""""""""""""""
"  .vimrc vim config file  "
"         by NoWiS         "
"                          "
"  last modif :            "
"    sam. 15 nov. 2008     "
"    	  10:47:22 CET     "
""""""""""""""""""""""""""""    	  

" Configuration file for vim
"set runtimepath=/usr/share/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vimcurrent,/usr/share/vim/vimfiles/after,/usr/share/vim/addons/after,/usr/share/vim
set runtimepath=/usr/share/vim/vim,/usr/share/vim/vimfiles,~/.vim

" Normally we use vim-extensions.
" Comment the following lines for true vi-compatibility
set nocompatible	" Use Vim defaults instead of 100% vi compatibility
set backspace=indent,eol,start	" more powerful backspacing

" set some defaults for the editor
set linebreak		" Don't wrap words by default
set textwidth=0		" Don't wrap lines by default
set nobackup		" Don't keep a backup file
set viminfo='20,\"50	" read/write a .viminfo file, don't store more than
			" 50 lines of registers
set history=50		" keep 50 lines of command line history
set ruler		" show the cursor position all the time

" Suffixes that get lower priority when doing tab completion for filenames.
" These are files we are not likely to want to edit or read.
set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc

" We know xterm-debian is a color terminal
if &term =~ "xterm-debian" || &term =~ "xterm-xfree86"
  set t_Co=16
  set t_Sf=[3%dm
  set t_Sb=[4%dm
endif

" Syntax highlighting and colorschme
syn on
set syntax=on
colorscheme elflord

" indent and plugins (completion...)
filetype indent plugin on
set ai
set smartindent
set wildmode=longest,list
" the following line make vim transforming tab into spaces
set expandtab
set sw=2 "2 spaces indent

" coding style 
" set cinoptions={.5s,:.5s,+.5s,t0,g0,^-2,e-2,n-2,p2s,(0,=.5s formatoptions=croql cindent shiftwidth=4 tabstop=2
"set cinoptions=>.5s,:.5s,t0,g0,e-2,p2s,(0,=.5s formatoptions=croql cindent shiftwidth=4 tabstop=2
set cinoptions=>1s,:1s,t0,g0,e-2,p2s,(0,=1s formatoptions=croql cindent shiftwidth=2 tabstop=2
set ts=2

" for dark background
set background=dark

if has("autocmd")
 " Enabled file type detection
 " Use the default filetype settings. If you also want to load indent files
 " to automatically do language-dependent indenting add 'indent' as well.
 filetype plugin on
endif " has ("autocmd")

" Some Debian-specific things
if has("autocmd")
  augroup filetype
    au BufRead reportbug.*		set ft=mail
    au BufRead reportbug-*		set ft=mail
  augroup END
endif

" Set paper size from /etc/papersize if available (Debian-specific)
if filereadable("/etc/papersize")
  try
    let s:shellbak = &shell
    let &shell="/bin/sh"
    let s:papersize = matchstr(system("cat /etc/papersize"), "\\p*")
    let &shell=s:shellbak
    if strlen(s:papersize)
      let &printoptions = "paper:" . s:papersize
    endif
  catch /^Vim\%((\a\+)\)\=:E145/
  endtry
endif

" The following are commented out as they cause vim to behave a lot
" different from regular vi. They are highly recommended though.
"set showcmd		" Show (partial) command in status line.
set showmatch		" Show matching brackets.
"set ignorecase		" Do case insensitive matching
"set incsearch		" Incremental search
"set autowrite		" Automatically save before commands like :next and :make

" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
  source /etc/vim/vimrc.local
endif

" Spelling
"set spelllang=en
"set spell
"set spellsuggest=5

" keyboard/mouse
set mouse=a
set selection=inclusive

" completion
imap <C-Space> <C-X><C-O>
iab #i #include
function! SmartTab()
  if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
    return "\<Tab>"
  else
    return "\<C-N>"
endfunction
inoremap <Tab> <C-R>=SmartTab()<CR>

" split
map <F4> <C-w>+
map <F5> <C-w>-
map <F6> <C-w><
map <F7> <C-w>>

" remap C-Tags
map <F1> <C-]>

" Tabs
map <A-Right> gt
map <A-Left> gT

" Replace
nmap <F3> :%s/\<<C-R>=expand("<cword>")<CR>\>//g<Left><Left>
vmap <F3> ygv:<C-U>%s/\<<C-R>"\>//g<Left><Left>>

" Java
let java_comment_strings=1
let java_highlight_java_lang_ids=1
let java_mark_braces_in_parens_as_errors=1
let java_highlight_all=1
let java_highlight_debug=1
let java_ignore_javadoc=1
let java_highlight_java_lang_ids=1
let java_highlight_functions="style"
let java_minlines = 150

" Auto brackets
noremap "" ""<Esc>i
inoremap ""; "";<Esc>hi
inoremap '' ''<Esc>i
inoremap ''; '';<Esc>hi

inoremap << <><Esc>i
inoremap </ </><Esc>i
inoremap <</ </><Esc>hi
inoremap <<! <!--  --><Esc>hhhi

inoremap (( ()<Left>
inoremap (<CR> (<CR>)<C-o>O
inoremap (; ();<Esc>hi
inoremap (<CR>; (<CR>);<C-o>O
inoremap ('; ('');<Esc>hhi
inoremap ("; ("");<Esc>hhi
inoremap (' ('')<Esc>hi
inoremap (" ("")<Esc>hi

inoremap {{ {}<Left>
inoremap {<CR> {<CR>}<C-o>O
inoremap {; {};<Esc>hi
inoremap {<CR>; {<CR>};<C-o>O
inoremap {'; {''};<Esc>hhi
inoremap {"; {""};<Esc>hhi
inoremap {' {''}<Esc>hi
inoremap {" {""}<Esc>hi
inoremap {{{ {{{ }}}<Esc>hhhi
inoremap {{{<CR> {{{ <CR>}}}<Esc>kA

inoremap [[ []<Left>
inoremap [<CR> [<CR>]<C-o>O
inoremap [; [];<Esc>hi
inoremap [<CR>; [<CR>];<C-o>O
inoremap ['; [''];<Esc>hhi
inoremap ["; [""];<Esc>hhi
inoremap [' ['']<Esc>hi
inoremap [" [""]<Esc>hi

